<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Polyfill</title>
</head>

<body>
    <h1>Polyfill</h1>
    <script>
        let data = [1, 2, 3, 4];
        it = makeIterator(data);

        console.log(it.next());
        console.log(it.next());
        console.log(it.next());
        console.log(it.next());
        console.log(it.next());

        function makeIterator(data) {
            const len = data.length;
            let index = 0;
            const next = () => {
                if (index >= len) {
                    return {
                        done: true
                    }
                } else {
                    return {
                        value: data[index++]
                    };
                }
            };

            return {
                next
            };
        }
    </script>
</body>

</html>